<html>
<script>

var INPUT = [[1,2,3], [4,5,6], [7,8,9]];
function reduceDimension(arr){
    var reduced = [];
    for(var i = 0;i < arr.length;i++){
        for(var j = 0;j < arr[i].length;j++){
            reduced.push(arr[i][j]);
        }
    }
    return reduced;
}

function getTwoDimensionArray(){
	return [[1,2,3], [4,5,6], [7,8,9]];
}

console.log(reduceDimension(INPUT));
/*
“concat creates a new array consisting of the elements in the object on which it is called, followed in order by, for each argument, the elements of that argument (if the argument is an array) or the argument itself (if the argument is not an array).”
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat

即如果concat方法的参数是一个元素，该元素会被直接插入到新数组中；如果参数是一个数组，该数组的各个元素将被插入到新数组中；将该特性应用到代码中：
*/
function reduceDimension2(arr){
    var reduced = [];
    for(var i = 0;i < arr.length;i++){
        reduced = reduced.concat(arr[i]);
    }
    return reduced;
}
console.log(reduceDimension2(INPUT));

/*
按照惯例，先来回顾一下MDN上对于apply方法的介绍：
“The apply() method calls a function with a given this value and arguments provided as an array.”
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply

即apply方法会调用一个函数，apply方法的第一个参数会作为被调用函数的this值，apply方法的第二个参数（一个数组，或类数组的对象）会作为被调用对象的arguments值，
也就是说,
<<该数组的各个元素>>将会依次成为被调用函数的各个参数；将该特性应用到代码中：

*/ 
function reduceDimension3(arr){
    return Array.prototype.concat.apply([],arr);
}
/*
arr作为apply方法的第二个参数，本身是一个数组，数组中的每一个元素（还是数组，即二维数组的第二维）会被作为参数依次传入到concat中，效果等同于[].concat([1,2], [3,4], [5,6])。*/

console.log(reduceDimension3(INPUT));

function log(a){
	debugger; // Jerry 2016-02-26 11:52AM 传入的还是[3,1,2], 
	// 但是a只接了3，剩下的1,2要log的实现自行从arguments中取出
	console.log("Jerry: " + a + this);
    var arguments = "Star Wars";
	console.log("Jerry: " + arguments);
}

var a = [3,1,2];
log.apply([], a);
console.log(Array.prototype.concat.apply([], [1,2,3]));
</script>
</html>